import {createWebHashHistory,createRouter} from "vue-router";

import homepage from "../view/homepage.vue"
import Concert from '../view/concert.vue';
import login from "../view/login.vue"
import index from "../view/index.vue"
import user from "../view/user.vue"
import manager from "../view/manager.vue"
import seat from "../view/seat.vue"
import order from "../view/order.vue"
import venue from "../view/venue.vue"
import Iconcert from "@/view/Iconcert.vue";
import UserProfile from '@/view/userProfile.vue';
import UserOrders from '@/view/userOrders.vue';
import pay from "../view/pay.vue"
import deepseek from "../view/deepseek.vue"


const routes = [
    {
        path: '/',
        name: 'homepage',
        component: homepage
    },
    {
        path: '/concert/:id',
        name: 'ConcertDetail',
        component: Concert,
        props: true,
    },
    {
        path: '/pay/:id',
        name: 'pay',
        component: pay,
        props: true,
    },

    {
        path: '/deepseek',component: deepseek
    },
    {
        path: '/login',
        name: 'login',
        component: login
    },
    {
        path: '/user/profile',
        name: 'UserProfile',
        component: UserProfile,
        // meta: { requiresAuth: true }
    },
    {
        path: '/user/orders',
        name: 'UserOrders',
        component: UserOrders,
        // meta: { requiresAuth: true }
    },
    {
        path: '/index',
        name: 'index',
        component: index,
        children: [
            {
                path: '/user',
                name: 'user',
                component: user
            },
            {
                path: '/manager',
                name: 'manager',
                component: manager
            },
            {
                path: '/seat',
                name: 'seat',
                component: seat
            },
            {
                path: '/order',
                name: 'order',
                component: order
            },
            {
                path: '/venue',
                name: 'venue',
                component: venue
            },
            {
                path: '/iconcert',
                name: 'iconcert',
                component: Iconcert
            }

        ]
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
});
// 路由守卫
router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token');
    if (to.meta.requiresAuth && !token) {
        next('/login');
    } else {
        next();
    }
});
export default router;